<!DOCTYPE html>
<html lang="zh-CN">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
  <meta name="apple-mobile-web-app-capable" content="yes">
  <meta name="apple-mobile-web-app-status-bar-style" content="black-translucent">
  <title>首页 - 积分商城</title>
  <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/normalize.css@8.0.1/normalize.min.css">
  <link rel="stylesheet" href="css/style.css">

  <style>
    /* 基础样式 */
    * {
      box-sizing: border-box;
      margin: 0;
      padding: 0;
      -webkit-tap-highlight-color: transparent;
    }
    
    body {
      font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
      font-size: 14px;
      color: #333;
      background-color: #f5f5f5;
      line-height: 1.5;
      overflow-x: hidden;
    }
    
    a {
      text-decoration: none;
      color: inherit;
    }
    
    img {
      max-width: 100%;
      vertical-align: middle;
      border-style: none;
    }
    
    input, button {
      font-family: inherit;
      font-size: inherit;
      outline: none;
      border: none;
      background: none;
    }
    
    /* 布局容器 */
    .app-container {
      max-width: 100%;
      margin: 0 auto;
      padding-bottom: 50px; /* 为底部导航留出空间 */
    }
    
    /* 搜索栏 */
    .search-bar {
      padding: 10px 15px;
      position: sticky;
      top: 0;
      z-index: 10;
      background-color: #fff;
      box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05);
    }
    
    .search-box {
      display: flex;
      align-items: center;
      background: #f5f5f5;
      border-radius: 20px;
      padding: 8px 15px;
      transition: all 0.3s;
    }
    
    .search-box:active {
      background: #e5e5e5;
    }
    
    .search-icon {
      margin-right: 8px;
      color: #666;
      font-size: 16px;
    }
    
    .search-input {
      flex: 1;
      font-size: 14px;
      color: #333;
    }
    
    /* 轮播图 */
    .banner-container {
      position: relative;
      width: 100%;
      height: 0;
      padding-bottom: 40%; /* 宽高比 5:2 */
      overflow: hidden;
      margin: 10px 0;
      border-radius: 8px;
      background-color: #eee;
    }
    
    .banner-wrapper {
      position: absolute;
      top: 0;
      left: 0;
      width: 100%;
      height: 100%;
    }
    
    .banner-slide {
      position: absolute;
      width: 100%;
      height: 100%;
      opacity: 0;
      transition: opacity 0.5s ease;
      background-size: cover;
      background-position: center;
    }
    
    .banner-slide.active {
      opacity: 1;
    }
    
    .banner-dots {
      position: absolute;
      bottom: 10px;
      left: 0;
      right: 0;
      display: flex;
      justify-content: center;
      gap: 8px;
      z-index: 1;
    }
    
    .banner-dot {
      width: 6px;
      height: 6px;
      border-radius: 50%;
      background: rgba(255, 255, 255, 0.5);
      transition: all 0.3s;
    }
    
    .banner-dot.active {
      width: 16px;
      border-radius: 3px;
      background: white;
    }
    
    /* 快捷入口 */
    .quick-actions {
      display: grid;
      grid-template-columns: repeat(4, 1fr);
      gap: 15px 0;
      padding: 15px;
      background: white;
      margin-bottom: 10px;
    }
    
    .quick-action {
      display: flex;
      flex-direction: column;
      align-items: center;
      text-decoration: none;
      color: #333;
    }
    
    .action-icon {
      width: 40px;
      height: 40px;
      background: linear-gradient(135deg, #ff5e57, #ff9966);
      border-radius: 50%;
      display: flex;
      align-items: center;
      justify-content: center;
      margin-bottom: 5px;
      font-size: 20px;
      color: white;
      box-shadow: 0 2px 5px rgba(255, 94, 87, 0.2);
    }
    
    .action-text {
      font-size: 12px;
      text-align: center;
    }
    
    /* 商品区域 */
    .section-container {
      background: white;
      margin-bottom: 10px;
    }
    
    .section-title {
      display: flex;
      justify-content: space-between;
      align-items: center;
      padding: 15px;
      font-size: 16px;
      font-weight: bold;
      border-bottom: 1px solid #f0f0f0;
    }
    
    .see-all {
      font-size: 12px;
      color: #666;
      font-weight: normal;
      display: flex;
      align-items: center;
    }
    
    .see-all::after {
      content: ">";
      margin-left: 3px;
    }
    
    .product-grid {
      display: grid;
      grid-template-columns: repeat(2, 1fr);
      gap: 10px;
      padding: 10px;
    }
    
    .product-card {
      background: white;
      border-radius: 8px;
      overflow: hidden;
      box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05);
      transition: transform 0.2s, box-shadow 0.2s;
    }
    
    .product-card:active {
      transform: translateY(2px);
      box-shadow: 0 1px 1px rgba(0, 0, 0, 0.1);
    }
    
    .product-image-container {
      position: relative;
      width: 100%;
      height: 0;
      padding-bottom: 100%;
      overflow: hidden;
      background: #f9f9f9;
    }
    
    .product-image {
      position: absolute;
      top: 0;
      left: 0;
      width: 100%;
      height: 100%;
      object-fit: cover;
      transition: transform 0.3s;
    }
    
    .product-card:hover .product-image {
      transform: scale(1.05);
    }
    
    .product-info {
      padding: 10px;
    }
    
    .product-title {
      font-size: 13px;
      margin-bottom: 8px;
      display: -webkit-box;
      -webkit-line-clamp: 2;
      -webkit-box-orient: vertical;
      overflow: hidden;
      height: 36px;
      line-height: 18px;
    }
    
    .product-price {
      display: flex;
      align-items: baseline;
    }
    
    .product-current-price {
      color: #f03d3d;
      font-weight: bold;
      font-size: 16px;
    }
    
    .product-original-price {
      color: #999;
      font-size: 12px;
      text-decoration: line-through;
      margin-left: 5px;
    }
    
    .product-points {
      margin-top: 5px;
      font-size: 12px;
      color: #ff9500;
    }
    
    /* 加载更多 */
    .load-more {
      text-align: center;
      padding: 15px;
      color: #666;
      font-size: 13px;
      background: white;
    }
    
    .load-more-btn {
      display: inline-block;
      padding: 8px 20px;
      border-radius: 15px;
      background: #f5f5f5;
      color: #666;
    }
    
    /* 底部导航 */
    .bottom-nav {
      position: fixed;
      bottom: 0;
      left: 0;
      right: 0;
      height: 50px;
      background: white;
      display: flex;
      border-top: 1px solid #f0f0f0;
      z-index: 100;
    }
    
    .nav-item {
      flex: 1;
      display: flex;
      flex-direction: column;
      align-items: center;
      justify-content: center;
      color: #666;
      font-size: 10px;
    }
    
    .nav-item.active {
      color: #ff5e57;
    }
    
    .nav-icon {
      font-size: 20px;
      margin-bottom: 2px;
    }
    
    /* 骨架屏 */
    .skeleton {
      background: linear-gradient(90deg, #f2f2f2 25%, #e6e6e6 37%, #f2f2f2 63%);
      background-size: 400% 100%;
      animation: skeleton-loading 1.4s ease infinite;
      border-radius: 4px;
    }
    
    @keyframes skeleton-loading {
      0% {
        background-position: 100% 50%;
      }
      100% {
        background-position: 0 50%;
      }
    }
    
    /* 响应式调整 */
    @media (min-width: 768px) {
      .app-container {
        max-width: 768px;
      }
      
      .banner-container {
        padding-bottom: 30%;
      }
      
      .quick-actions {
        grid-template-columns: repeat(8, 1fr);
      }
    }
    
    /* 动画效果 */
    @keyframes fadeIn {
      from { opacity: 0; }
      to { opacity: 1; }
    }
    
    .fade-in {
      animation: fadeIn 0.5s ease forwards;
    }
  </style>
</head>
<body>
<div class="app-container">
  <!-- 搜索栏 -->
  <div class="search-bar">
    <div class="search-box">
      <span class="search-icon">🔍</span>
      <input type="text" class="search-input" placeholder="搜索商品..." id="searchInput">
    </div>
  </div>

  <!-- 轮播图 -->
  <div class="banner-container">
    <div class="banner-wrapper">
      <div class="banner-slide active" style="background-image: url('https://picsum.photos/800/400?random=1')"></div>
      <div class="banner-slide" style="background-image: url('https://picsum.photos/800/400?random=2')"></div>
      <div class="banner-slide" style="background-image: url('https://picsum.photos/800/400?random=3')"></div>
      <div class="banner-dots">
        <div class="banner-dot active"></div>
        <div class="banner-dot"></div>
        <div class="banner-dot"></div>
      </div>
    </div>
  </div>

  <!-- 快捷入口 -->
  <div class="quick-actions">
    <a href="#" class="quick-action">
      <div class="action-icon">📱</div>
      <div class="action-text">数码</div>
    </a>
    <a href="#" class="quick-action">
      <div class="action-icon">👕</div>
      <div class="action-text">服饰</div>
    </a>
    <a href="#" class="quick-action">
      <div class="action-icon">🛒</div>
      <div class="action-text">超市</div>
    </a>
    <a href="#" class="quick-action">
      <div class="action-icon">🍔</div>
      <div class="action-text">美食</div>
    </a>
    <a href="#" class="quick-action">
      <div class="action-icon">🏠</div>
      <div class="action-text">家居</div>
    </a>
    <a href="#" class="quick-action">
      <div class="action-icon">✈️</div>
      <div class="action-text">旅行</div>
    </a>
    <a href="#" class="quick-action">
      <div class="action-icon">🎁</div>
      <div class="action-text">礼券</div>
    </a>
    <a href="#" class="quick-action">
      <div class="action-icon">➕</div>
      <div class="action-text">全部</div>
    </a>
  </div>

  <!-- 热门推荐 -->
  <div class="section-container">
    <div class="section-title">
      <span>热门推荐</span>
      <a href="#" class="see-all">查看全部</a>
    </div>
    <div class="product-grid" id="productGrid">
      <!-- 商品将通过JavaScript动态加载 -->
    </div>
    <div class="load-more">
      <div class="load-more-btn" id="loadMoreBtn">点击加载更多</div>
    </div>
  </div>

  <!-- 积分兑换 -->
  <div class="section-container">
    <div class="section-title">
      <span>积分兑换</span>
      <a href="#" class="see-all">查看全部</a>
    </div>
    <div class="product-grid" id="pointsProductGrid">
      <!-- 积分商品将通过JavaScript动态加载 -->
    </div>
  </div>
</div>

<!-- 底部导航 -->
<!-- <div class="bottom-nav">
  <a href="index.html" class="nav-item active">
    <div class="nav-icon">🏠</div>
    <div>首页</div>
  </a>
  <a href="mall.html" class="nav-item">
    <div class="nav-icon">🛒</div>
    <div>商城</div>
  </a>
  <a href="points.html" class="nav-item">
    <div class="nav-icon">💳</div>
    <div>积分</div>
  </a>
  <a href="profile.html" class="nav-item">
    <div class="nav-icon">👤</div>
    <div>我的</div>
  </a>
</div> -->

<!-- 导航栏容器 -->
<div id="navbar-container"></div>

 <!-- 一次性引入合并后的JS -->
<script src="./js/navbar-loader.js"></script>

<script src="js/common.js"></script>


<script>
  // 商品数据
  const products = [
    { 
      id: 1, 
      name: "Apple iPhone 13 5G手机 128GB", 
      price: 5999, 
      originalPrice: 6799, 
      image: "https://picsum.photos/300/300?random=101",
      points: 5999
    },
    { 
      id: 2, 
      name: "小米12 Pro 5G智能手机", 
      price: 4699, 
      originalPrice: 4999, 
      image: "https://picsum.photos/300/300?random=102",
      points: 4699
    },
    { 
      id: 3, 
      name: "华为MateBook 14 2022款", 
      price: 5999, 
      originalPrice: 6499, 
      image: "https://picsum.photos/300/300?random=103",
      points: 5999
    },
    { 
      id: 4, 
      name: "索尼PS5游戏主机", 
      price: 3899, 
      originalPrice: 4299, 
      image: "https://picsum.photos/300/300?random=104",
      points: 3899
    },
    { 
      id: 5, 
      name: "戴尔27英寸4K显示器", 
      price: 2799, 
      originalPrice: 2999, 
      image: "https://picsum.photos/300/300?random=105",
      points: 2799
    },
    { 
      id: 6, 
      name: "Bose QuietComfort 45耳机", 
      price: 2299, 
      originalPrice: 2499, 
      image: "https://picsum.photos/300/300?random=106",
      points: 2299
    },
    { 
      id: 7, 
      name: "罗技MX Master 3鼠标", 
      price: 599, 
      originalPrice: 699, 
      image: "https://picsum.photos/300/300?random=107",
      points: 599
    },
    { 
      id: 8, 
      name: "三星980 PRO 1TB SSD", 
      price: 999, 
      originalPrice: 1199, 
      image: "https://picsum.photos/300/300?random=108",
      points: 999
    }
  ];

  // 积分商品数据
  const pointsProducts = [
    { 
      id: 101, 
      name: "星巴克中杯兑换券", 
      price: 0, 
      originalPrice: 35, 
      image: "https://picsum.photos/300/300?random=201",
      points: 500
    },
    { 
      id: 102, 
      name: "腾讯视频月卡", 
      price: 0, 
      originalPrice: 30, 
      image: "https://picsum.photos/300/300?random=202",
      points: 300
    },
    { 
      id: 103, 
      name: "京东20元优惠券", 
      price: 0, 
      originalPrice: 20, 
      image: "https://picsum.photos/300/300?random=203",
      points: 200
    },
    { 
      id: 104, 
      name: "爱奇艺黄金周卡", 
      price: 0, 
      originalPrice: 15, 
      image: "https://picsum.photos/300/300?random=204",
      points: 150
    }
  ];

  // DOM加载完成后执行
  document.addEventListener('DOMContentLoaded', () => {
    // 获取DOM元素
    const productGrid = document.getElementById('productGrid');
    const pointsProductGrid = document.getElementById('pointsProductGrid');
    const loadMoreBtn = document.getElementById('loadMoreBtn');
    const bannerSlides = document.querySelectorAll('.banner-slide');
    const bannerDots = document.querySelectorAll('.banner-dot');
    const searchInput = document.getElementById('searchInput');

    // 当前显示的商品数量
    let visibleProducts = 4;

    // 渲染商品列表
    function renderProducts() {
      productGrid.innerHTML = '';

      const productsToShow = products.slice(0, visibleProducts);

      productsToShow.forEach(product => {
        const card = document.createElement('div');
        card.className = 'product-card fade-in';
        card.innerHTML = `
          <div class="product-image-container">
            <img src="${product.image}" alt="${product.name}" class="product-image" loading="lazy">
          </div>
          <div class="product-info">
            <div class="product-title">${product.name}</div>
            <div class="product-price">
              <span class="product-current-price">¥${product.price.toLocaleString()}</span>
              <span class="product-original-price">¥${product.originalPrice.toLocaleString()}</span>
            </div>
            <div class="product-points">可用${product.points}积分抵扣</div>
          </div>
        `;

        // 添加点击事件
        card.addEventListener('click', () => {
          // 实际项目中这里可以跳转到商品详情页
          showProductDetail(product);
        });

        productGrid.appendChild(card);
      });
    }

    // 渲染积分商品
    function renderPointsProducts() {
      pointsProductGrid.innerHTML = '';

      pointsProducts.forEach(product => {
        const card = document.createElement('div');
        card.className = 'product-card fade-in';
        card.innerHTML = `
          <div class="product-image-container">
            <img src="${product.image}" alt="${product.name}" class="product-image" loading="lazy">
          </div>
          <div class="product-info">
            <div class="product-title">${product.name}</div>
            <div class="product-price">
              <span class="product-points">${product.points}积分</span>
              <span class="product-original-price">价值¥${product.originalPrice.toLocaleString()}</span>
            </div>
          </div>
        `;

        // 添加点击事件
        card.addEventListener('click', () => {
          showProductDetail(product);
        });

        pointsProductGrid.appendChild(card);
      });
    }

    // 显示商品详情
    function showProductDetail(product) {
      // 这里可以替换为实际的页面跳转或弹窗
      alert(`即将跳转到 ${product.name} 详情页\nID: ${product.id}`);
      // window.location.href = `product.html?id=${product.id}`;
    }

    // 初始渲染
    renderProducts();
    renderPointsProducts();

    // 加载更多商品
    loadMoreBtn.addEventListener('click', () => {
      visibleProducts += 4;
      if (visibleProducts >= products.length) {
        loadMoreBtn.textContent = "没有更多了";
        loadMoreBtn.style.opacity = "0.6";
        loadMoreBtn.disabled = true;
      }
      renderProducts();
      
      // 滚动到新加载的商品位置
      const newItems = productGrid.querySelectorAll('.fade-in');
      if (newItems.length > 0) {
        newItems[newItems.length - 1].scrollIntoView({
          behavior: 'smooth',
          block: 'nearest'
        });
      }
    });

    // 轮播图逻辑
    let currentSlide = 0;
    let slideInterval;

    function showSlide(index) {
      bannerSlides.forEach((slide, i) => {
        slide.classList.toggle('active', i === index);
      });

      bannerDots.forEach((dot, i) => {
        dot.classList.toggle('active', i === index);
      });
    }

    function nextSlide() {
      currentSlide = (currentSlide + 1) % bannerSlides.length;
      showSlide(currentSlide);
    }

    // 启动自动轮播
    function startSlideShow() {
      slideInterval = setInterval(nextSlide, 3000);
    }

    // 停止自动轮播
    function stopSlideShow() {
      clearInterval(slideInterval);
    }

    // 初始化轮播
    startSlideShow();

    // 鼠标悬停暂停轮播
    document.querySelector('.banner-container').addEventListener('mouseenter', stopSlideShow);
    document.querySelector('.banner-container').addEventListener('mouseleave', startSlideShow);

    // 触摸事件处理
    let touchStartX = 0;
    let touchEndX = 0;
    
    document.querySelector('.banner-container').addEventListener('touchstart', (e) => {
      touchStartX = e.changedTouches[0].screenX;
      stopSlideShow();
    }, {passive: true});
    
    document.querySelector('.banner-container').addEventListener('touchend', (e) => {
      touchEndX = e.changedTouches[0].screenX;
      handleSwipe();
      startSlideShow();
    }, {passive: true});
    
    function handleSwipe() {
      const threshold = 50;
      if (touchEndX < touchStartX - threshold) {
        // 向左滑动 - 下一张
        nextSlide();
      } else if (touchEndX > touchStartX + threshold) {
        // 向右滑动 - 上一张
        currentSlide = (currentSlide - 1 + bannerSlides.length) % bannerSlides.length;
        showSlide(currentSlide);
      }
    }

    // 点击指示器切换
    bannerDots.forEach((dot, index) => {
      dot.addEventListener('click', () => {
        currentSlide = index;
        showSlide(currentSlide);
        // 重置自动轮播计时器
        stopSlideShow();
        startSlideShow();
      });
    });

    // 搜索功能
    searchInput.addEventListener('keypress', (e) => {
      if (e.key === 'Enter' && e.target.value.trim()) {
        // 实际项目中可以跳转到搜索页
        alert(`搜索: ${e.target.value}`);
        // window.location.href = `search.html?q=${encodeURIComponent(e.target.value)}`;
      }
    });

    // 防止快速点击
    function preventFastClick(selector, callback) {
      let lastClickTime = 0;
      const elements = document.querySelectorAll(selector);
      
      elements.forEach(el => {
        el.addEventListener('click', (e) => {
          const now = Date.now();
          if (now - lastClickTime < 1000) return;
          lastClickTime = now;
          callback.call(el, e);
        });
      });
    }

    // 应用防快速点击
    preventFastClick('.product-card', function(e) {
      const productId = this.dataset.id;
      showProductDetail(products.find(p => p.id == productId));
    });

    // 添加骨架屏效果
    function addSkeleton() {
      const skeletonHtml = `
        <div class="product-card">
          <div class="product-image-container skeleton" style="height: 120px;"></div>
          <div class="product-info">
            <div class="product-title skeleton" style="height: 36px; width: 100%;"></div>
            <div class="product-price">
              <span class="skeleton" style="display: inline-block; width: 60px; height: 16px;"></span>
              <span class="skeleton" style="display: inline-block; width: 40px; height: 12px; margin-left: 5px;"></span>
            </div>
          </div>
        </div>
      `;
      
      // 初始加载时显示骨架屏
      productGrid.innerHTML = skeletonHtml.repeat(4);
      pointsProductGrid.innerHTML = skeletonHtml.repeat(4);
      
      // 模拟数据加载延迟
      setTimeout(() => {
        renderProducts();
        renderPointsProducts();
      }, 800);
    }

    // 初始加载显示骨架屏
    addSkeleton();
  });
</script>
</body>
</html>